/// @tags: SegmentTree TD
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
#define rint register int

using std::cin;
using std::cout;
using std::make_pair;
using std::swap;

namespace BlueQuantum {

typedef long long LL;
typedef std::pair<LL, int> PLI;

constexpr int maxn = 5e4 + 3, maxa = maxn, segn = maxn * 256, mod = 1e9 + 7;

inline void operator+=(PLI &lhs, const PLI &rhs) {
  lhs.first += rhs.first;
  lhs.second += rhs.second;
}

int cnt[segn], ls[segn], rs[segn];
LL sum[segn];
std::stack<int> rec;

inline void destroy(int &k) {
  sum[k] = cnt[k] = ls[k] = rs[k] = 0;
  rec.push(k);
  k = 0;
}

inline int allocate() {
  static int segcnt = 0;
  if (rec.empty()) return ++segcnt;
  int res = rec.top();
  rec.pop();
  return res;
}

void modify(int &u, int l, int r, int pos, int x, int y) {
  if (!u) u = allocate();
  (sum[u] += x + mod) %= mod, cnt[u] += y;
  if (l == r) {
    if (cnt[u] == 0) destroy(u);
    return;
  }
  int mid = (l + r) >> 1;
  pos <= mid ? modify(ls[u], l, mid, pos, x, y) : modify(rs[u], mid + 1, r, pos, x, y);
  if (!cnt[u]) destroy(u);
}

PLI query(int u, int l, int r, int L, int R) {
  if (!u) return make_pair(0, 0);
  if (L <= l && r <= R) return make_pair(sum[u], cnt[u]);
  int mid = (l + r) >> 1;
  PLI res(0, 0);
  if (L <= mid) res += query(ls[u], l, mid, L, R);
  if (mid < R) res += query(rs[u], mid + 1, r, L, R);
  return res;
}

int root[segn];

void modify(int u, int l, int r, int pos, int x, int page, int opt) {
  modify(root[u], 1, maxa, x, page, opt);
  if (l == r) return;
  int mid = (l + r) >> 1;
  pos <= mid ? modify(u << 1, l, mid, pos, x, page, opt)
             : modify(u << 1 | 1, mid + 1, r, pos, x, page, opt);
}

PLI query(int u, int l, int r, int x, int y, int L, int R) {
  if (x <= l && r <= y) return query(root[u], 1, maxa, L, R);
  int mid = (l + r) >> 1;
  PLI res(0, 0);
  if (x <= mid) res += query(u << 1, l, mid, x, y, L, R);
  if (mid < y) res += query(u << 1 | 1, mid + 1, r, x, y, L, R);
  res.first %= mod;
  return res;
}

int a[maxn], page[maxn];

inline int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> page[i];
  }
  for (int i = 1; i <= n; ++i) modify(1, 1, n, i, a[i], page[i], 1);
  LL ans = 0;
  for (int i = 1; i <= n; ++i) {
    PLI cur = query(1, 1, n, i + 1, n, 1, a[i]);
    (ans += (LL)page[i] * cur.second + cur.first) %= mod;
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (x == y) {
      cout << ans << '\n';
      continue;
    }
    if (x > y) swap(x, y);
    int L = a[x], R = a[y], min = std::min(L, R), max = std::max(L, R);
    PLI res;
    res = query(1, 1, n, x, y, min + 1, max - 1);
    ans += (min == L ? 1 : -1) * (2 * res.first % mod + (LL)(res.second + 1) * (page[x] + page[y]));
    ans %= mod;
    res = query(1, 1, n, x, y, 1, min - 1);
    (ans += (LL)res.second * (page[y] - page[x])) %= mod;
    res = query(1, 1, n, x, y, max + 1, n);
    (ans += (LL)res.second * (page[x] - page[y])) %= mod;
    if (ans < 0) ans += mod;
    cout << ans << '\n';
    modify(1, 1, n, x, a[x], -page[x], -1);
    modify(1, 1, n, y, a[y], -page[y], -1);
    modify(1, 1, n, x, a[y], page[y], 1);
    modify(1, 1, n, y, a[x], page[x], 1);
    swap(a[x], a[y]), swap(page[x], page[y]);
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P3759 [TJOI2017] 不勤劳的图书管理员.in", "r", stdin);
  freopen("P3759 [TJOI2017] 不勤劳的图书管理员.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
